package com.exam.service.impl;

import com.exam.dao.IReservationDao;
import com.exam.service.ReservationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ReservationServiceImpl implements ReservationService {

	@Resource
	private IReservationDao reservationDao;

	/**
	 * 查询当前用户的未过期考试信息
	 */
	@Override
	public List<Map<String, Object>> getReservationPerStuInDate(String sno) {
		return reservationDao.getReservationPerStuInDate(sno);
	}

	/**
	 * 查询当前用户的过期考试信息
	 */
	@Override
	public List<Map<String, Object>> getReservationPerStuOutOfDate(String sno) {
		return reservationDao.getReservationPerStuOutOfDate(sno);
	}

	/**
	 * 预约考试，考试编号，学号
	 */
	@Override
	public int reserveExam(int eid, String sno) {
		int res = reservationDao.reserveExam(eid,sno);//预约
		reservationDao.updateExamination(eid);//当前考试的预约人数加一
		return res;
	}

	/**
	 * 取消预约
	 * @return
	 */
	@Override
	public int cancelReservation(String eid, String sno) {
		int result=reservationDao.cancelReservation(eid,sno);//取消预约
		reservationDao.downExamination(eid);//更新考试表
		return result;
	}

	/**
	 * 删除历史预约
	 */
	@Override
	public int removeReservation(String eid, String sno) {//删除历史预约
		return reservationDao.removeReservation(eid,sno);
	}

	/**
	 *	未过期的预约
	 */
	@Override
	public List<Map<String, Object>> getAllReservationInDate() {
		return reservationDao.getAllReservationInDate();
	}

	/**
	 * 所有过期的预约
	 */
	@Override
	public List<Map<String, Object>> getAllReservationOutOfDate() {
		return reservationDao.getAllReservationOutOfDate();
	}

	public void setReservationDao(IReservationDao reservationDao) {
		this.reservationDao = reservationDao;
	}
}
